////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                                //
//                      Single Linked List's find, insert, delete, functions' implemention code                //
//                                                                                                                                //
//                                                                                                                                //
//                                      Author:    Jack Hui (huiguobin)                                                 //
//                                                                                                                                //
//                                                                                                                                //
////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////Test File//////////////////////////////////////////////

//#define switch____
#ifdef switch____

#include "single_linked_list.h"

int main()
{ 
 	LinkedNode *node_head;
	LinkedNode *node1;
	LinkedNode *node2;
	LinkedNode *node3;
	LinkedNode *key_node;
	int rst;
	int insert_pos;
   	DataType value;
	int delete_pos;
	
	/*Create a Single Linked List(With three nodes: value 1, 4, 7)*/
	node_head = (LinkedNode *)malloc(sizeof(LinkedNode));
	node_head->data = 0;
	node1 = (LinkedNode *)malloc(sizeof(LinkedNode));
	node2 = (LinkedNode *)malloc(sizeof(LinkedNode));
	node3 = (LinkedNode *)malloc(sizeof(LinkedNode));
	node1->data = 1;
	node2->data = 4;
	node3->data = 7;
	node1->link = node2;
	node2->link = node3;
	node3->link = NULL;
	node_head->link = node1;

	/*Find the second node and print*/
	key_node = find_list(node_head, 2);
	if(NULL == key_node)
	{
		printf("find error!\n");
	}
	printf("the key node is:");
	printf("%d\n", key_node->data);

	/*Insert a node before the second node,value 456, and print it out.*/
	insert_pos = 2;
	value = 456;
	rst = insert_list(node_head, insert_pos, value);
	if(rst == 0)
	{
		printf("insert error!\n");
	}
	printf("the inserted position is: %d\n", insert_pos);
	printf("the inserted number is: %d\n\n", (find_list(node_head, insert_pos))->data);

	/*Delete the second node, and print the informantion.*/
	delete_pos = 3;
	printf("before delete, the NO.%d node value is : %d\n", delete_pos, (find_list(node_head, delete_pos))->data);
	rst = delete_list(node_head, delete_pos);
	if(rst == 0)
	{
		printf("delete error!\n");
	}
	printf("after delete, the NO.%d node value is : %d\n", delete_pos, (find_list(node_head, delete_pos))->data);
	
	return 0;
}

#endif

